package cn.coastalinfo.project.drools.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.coastalinfo.framework.aspectj.lang.annotation.Log;
import cn.coastalinfo.framework.aspectj.lang.enums.BusinessType;
import cn.coastalinfo.project.drools.domain.vo.RuleVariableVo;
import cn.coastalinfo.project.drools.domain.bo.RuleVariableBo;
import cn.coastalinfo.project.drools.service.IRuleVariableService;
import cn.coastalinfo.framework.web.controller.BaseController;
import cn.coastalinfo.framework.web.domain.AjaxResult;
import cn.coastalinfo.common.utils.poi.ExcelUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;


import cn.coastalinfo.framework.web.page.TableDataInfo;

import java.util.Arrays;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * 参数Controller
 * 
 * @author hadge
 * @date 2024-06-07
 */
@Api("参数管理")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/drools/variable")
public class RuleVariableController extends BaseController
{
    @Autowired
    private IRuleVariableService ruleVariableService;

    /**
     * 查询参数列表
     */
    @ApiOperation("获取参数列表")
    //@PreAuthorize("@ss.hasPermi('drools:variable:list')")
    @GetMapping("/list")
    public TableDataInfo list(RuleVariableBo ruleVariableBo)
    {
        startPage();
        List<RuleVariableVo> list = ruleVariableService.queryList(ruleVariableBo);
        return getDataTable(list);
    }

    /**
     * 导出参数列表
     */
    //@PreAuthorize("@ss.hasPermi('drools:variable:export')")
    @Log(title = "参数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RuleVariableBo ruleVariableBo)
    {
        List<RuleVariableVo> list = ruleVariableService.queryList(ruleVariableBo);
        ExcelUtil<RuleVariableVo> util = new ExcelUtil<RuleVariableVo>(RuleVariableVo.class);
        util.exportExcel(response, list, "参数数据");
    }

    /**
     * 获取参数详细信息
     */
    @ApiOperation("获取参数详情")
    //@PreAuthorize("@ss.hasPermi('drools:variable:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id)
    {
        return success(ruleVariableService.queryById(id));
    }

    /**
     * 新增参数
     */
    @ApiOperation("添加参数")
    //@PreAuthorize("@ss.hasPermi('drools:variable:add')")
    @Log(title = "参数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RuleVariableBo ruleVariableBo)
    {
        return toAjax(ruleVariableService.insertByBo(ruleVariableBo));
    }

    /**
     * 修改参数
     */
    @ApiOperation("修改参数")
    //@PreAuthorize("@ss.hasPermi('drools:variable:edit')")
    @Log(title = "参数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RuleVariableBo ruleVariableBo)
    {
        return toAjax(ruleVariableService.updateByBo(ruleVariableBo));
    }

    /**
     * 删除参数
     */
    @ApiOperation("删除参数")
    //@PreAuthorize("@ss.hasPermi('drools:variable:remove')")
    @Log(title = "参数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids)
    {
        return toAjax(ruleVariableService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }

}
